package com.yanggu.jt808.handler;

import com.yanggu.jt808.annotation.Jt808Pack;
import com.yanggu.jt808.consts.Jt808Constant;
import com.yanggu.jt808.model.base.DataPackage;
import com.yanggu.jt808.model.base.Header;
import com.yanggu.jt808.model.req.T0100Msg;
import com.yanggu.jt808.model.resp.RegisterResp;
import lombok.extern.slf4j.Slf4j;

/**
 * 终端注册
 * 终端注册是为了建立终端和车辆的关系 注册获取鉴权码鉴权完成后才能传输
 */
@Slf4j
@Jt808Pack(msgId = Jt808Constant.终端注册)
public class Handler0x0100 implements PackHandler {


    @Override
    public DataPackage handle(DataPackage msg, int flowId) {
        Header header = msg.getHeader();

        //获取终端手机号
        String terminalPhone = header.getTerminalPhone();
        log.info("[终端注册 0x0100] 终端手机号: {}", terminalPhone);

        //解析消息体
        T0100Msg t0100Msg = new T0100Msg(msg);
        t0100Msg.parseBody();


        //组装响应信息
        RegisterResp registerResp = RegisterResp.response(msg, flowId);
        registerResp.setAuthCode("SUCCESS");
        registerResp.setResult(RegisterResp.SUCCESS);

        return registerResp;
    }


}
